﻿using System;
using System.Collections.Generic;
using Less.DAL;
using Less.Core;
using Less.Core.Model;

namespace Less.SRV
{
    public class LogSRV : IReadLogService, IWriteLogService
    {
        private readonly LogEntriesDAL logEntriesDAL;
        
        public LogSRV()
        {
            logEntriesDAL = new LogEntriesDAL();
        }

        public LogSRV(string connectionStringName)
        {
            logEntriesDAL = new LogEntriesDAL(new Database(connectionStringName));
        }

        public LogSRV(IDatabase database)
        {
            logEntriesDAL = new LogEntriesDAL(database);
        }
        #region IReadLogService Members
        public List<LogEntry> GetAll()
        {
            return logEntriesDAL.SelectAll();
        }

        public List<LogEntry> GetBySeverity(EntrySeverities severity)
        {
            return logEntriesDAL.SelectBySeverity(severity);
        }

        public List<LogEntry> GetByMinSeverity(EntrySeverities minSeverity)
        {
            return logEntriesDAL.SelectByMinSeverity(minSeverity);
        }

        public List<LogEntry> GetLast(int count)
        {
            return logEntriesDAL.SelectLast(count);
        }

        public List<LogEntriesBySeveritySummary> GetLogEntriesBySeveritySummary()
        {
            return logEntriesDAL.SelectLogEntriesBySeveritySummary();
        }
        #endregion
        #region IWriteLogService Members
        public void Insert(LogEntry logEntry)
        {
            if (logEntry == null)
            {
                throw new ArgumentNullException("logEntry");
            }
            logEntriesDAL.Insert(logEntry);
        }
        #endregion
    }
}